package com.mosai.smartmedical;

import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.mosai.smartmedical.util.QRCodeUtil;

public class QRCodeActivity extends AppCompatActivity {
    public static final String TAG = QRCodeActivity.class.getSimpleName();
    EditText etContent;
    ImageView ivQRCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: ");
        setContentView(R.layout.activity_qr_code);
        etContent = findViewById(R.id.etContent);
        ivQRCode = findViewById(R.id.ivQRCode);
    }

    public void onQRCode(View view) {
        Editable text = etContent.getText();
        if (text == null || text.toString().isEmpty()) {
            return;
        }
        int w = (int) (getResources().getDisplayMetrics().widthPixels * 0.8);
        Bitmap bitmap = QRCodeUtil.createQRCodeBitmap(text.toString(), w, w);
        ivQRCode.setImageBitmap(bitmap);
    }
}
